import sys
sys.path.append('..\\..')
from Djoser import *


root = Tk()
f1 = Frame(root)
f1.pack()

if False:
	fld = DjField(f1)
else:
	fld = DjField(f1, scrollbar=True)
fld.pack()

	
def test(n):
	if n==1: 
		fld.bgcolor=(200,255,255)
		print fld.bgcolor
	elif n==2:
		fld.color=(255,0,0)
		print fld.color
	elif n==3:
		fld.set_many(bgcolor=(200,255,255), color=(255,0,0))
	elif n==4: fld.text = 'hello'
	elif n==5: print fld.text
	elif n==6: fld.enabled = not fld.enabled
	elif n==7: 
		fld.borderwidth = 4
		print fld.borderwidth
	elif n==8:
		fld.font = ('Times New Roman', 12, 'normal')
		print fld.font
	elif n==9:
		fld.height=fld.width=10
		print fld.height, fld.width
	elif n==10:
		fld.wrap = 'none'
		print fld.wrap
	elif n==11:
		fld.highlight_chars(2,5) #highlight the chars
	elif n==12:
		fld.highlightcolor = (255,100,100)
		fld.highlight_line(1) #highlight the second line
	elif n==13:
		fld.borderstyle = 'raised'
	elif n==14: fld.set_alignment('all','center')
	elif n==15: fld.set_alignment(1,'right')
	elif n==16: fld.insert_text('some text')
	elif n==17:
		print 'Selected text:',fld.get_selected_text(),'Selected index:',fld.get_selection()
	elif n==18:
		fld.undo = True
		print fld.undo
	elif n==19:pass
	

f = Frame(root)
f.pack()
Button(f,text='Select all',command=lambda:fld.select_all()).pack(side=LEFT)
Button(f,text='Bgcolor',command=lambda:test(1)).pack(side=LEFT)
Button(f,text='color',command=lambda:test(2)).pack(side=LEFT)
Button(f,text='set many',command=lambda:test(3)).pack(side=LEFT)
Button(f,text='set Text',command=lambda:test(4)).pack(side=LEFT)
Button(f,text='get Text',command=lambda:test(5)).pack(side=LEFT)
Frame(f).pack(side=LEFT, padx=15)
Button(f,text='disable',command=lambda:test(6)).pack(side=LEFT)
Button(f,text='border width',command=lambda:test(7)).pack(side=LEFT)
Button(f,text='font',command=lambda:test(8)).pack(side=LEFT)
Button(f,text='height/width',command=lambda:test(9)).pack(side=LEFT)
Button(f,text='wrap',command=lambda:test(10)).pack(side=LEFT)
Frame(f).pack(side=LEFT, padx=15)
Button(f,text='highlight chars',command=lambda:test(11)).pack(side=LEFT)
Button(f,text='highlight line',command=lambda:test(12)).pack(side=LEFT)
Button(f,text='highlight clear',command=lambda:fld.highlight_clear()).pack(side=LEFT)
Button(f,text='borderstyle',command=lambda:test(13)).pack(side=LEFT)

f3 = Frame(root)
f3.pack()
Button(f3,text='align all',command=lambda:test(14)).pack(side=LEFT)
Button(f3,text='align line',command=lambda:test(15)).pack(side=LEFT)
Button(f3,text='insert text',command=lambda:test(16)).pack(side=LEFT)
Button(f3,text='selection',command=lambda:test(17)).pack(side=LEFT)
Button(f3,text='clear',command=lambda:fld.clear()).pack(side=LEFT)
Button(f3,text='scrolltop',command=lambda:fld.scrollto_start()).pack(side=LEFT)
Button(f3,text='scrollend',command=lambda:fld.scrollto_end()).pack(side=LEFT)
Frame(f3).pack(side=LEFT, padx=15)
Button(f3,text='undo on',command=lambda:test(18)).pack(side=LEFT)
Button(f3,text='undo!',command=lambda:fld.edit_undo()).pack(side=LEFT)
Button(f3,text='redo!',command=lambda:fld.edit_redo()).pack(side=LEFT)
Button(f3,text='deselect',command=lambda:fld.deselect()).pack(side=LEFT)

def testBadProps():
	# Make sure that we can't just arbitrarily set some weird property. That would allow misspellings.
	worked = False
	try:
		fld.someproperty = 2
	except AttributeError:
		worked = True
	if worked: print 'Test passed.'
	else: raise 'Test failed, set bad property.'
	worked = False
	try:
		x = fld.someproperty
	except AttributeError:
		worked = True
	if worked: print 'Test passed.'
	else: raise 'Test failed, getting bad property.'

testBadProps()
f.mainloop()